package jdk.cf;

import jdk.entity.UserEntity;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;


/**
 * 异步请求
 * @author songyafei
 */
public class CompletableFutureTest {
    public static void main(String[] args) {
        ArrayList<UserEntity> userEntities = new ArrayList<>();
        userEntities.add(new UserEntity(1L,18,"zhang", LocalDate.now(),Double.valueOf(1000)));
        userEntities.add(new UserEntity(2L,23,"li", LocalDate.now().minusYears(2),Double.valueOf(1000)));
        userEntities.add(new UserEntity(3L,22,"wang", LocalDate.now().minusYears(3),Double.valueOf(1000)));

        List<CompletableFuture<String>> collect = userEntities.stream().filter(m -> null != m.getUserId())
                .map(i -> CompletableFuture.supplyAsync(() -> i.getUserId() + ":" + i.getAge()))
                .collect(Collectors.toList());
        List<String> stringStream = collect.stream().map(CompletableFuture::join).collect(Collectors.toList());
        System.out.println(stringStream);


    }
}
